# -*- coding:utf-8 -*-
# https://wangzhangfei.blog.csdn.net/article/details/108952628
#

import os
import sys
import logging


def write_log(path1: str):
    """get"""
    logger2 = logging.getLogger()
    logger2.setLevel(logging.INFO)

    logfile = path1
    fh = logging.FileHandler(logfile, mode='a')
    fh.setLevel(logging.DEBUG)

    ch = logging.StreamHandler()
    ch.setLevel(logging.WARNING)

    formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s:%(message)s")

    fh.setFormatter(formatter)
    ch.setFormatter(formatter)

    logger2.addHandler(fh)
    logger2.addHandler(ch)

    logger2.debug('这是 {0}'.format('debug'))
    logger2.info('这是 {0}'.format('info'))
    logger2.warning('这是 {0}'.format('warning'))
    logger2.error('这是 {0}'.format('error'))
    logger2.critical('这是 {0}'.format('critical'))


if __name__ == "__main__":
    """1.log"""
    print("get log:")
    if len(sys.argv) <= 1:
        print("get log: error !")
        pass
    else:
        dir2 = sys.argv[1]
        print(os.path.dirname(dir2))
        if os.path.exists(dir2):
            pass
        else:
            dir2_dirname = os.path.dirname(dir2)
            os.mkdir(dir2_dirname)

        write_log(dir2)
